<html>
<head>
<meta NAME="author" CONTENT="Zsolt Mohacsi">
<link REL ="stylesheet" TYPE="text/css" HREF="../../../marvinmanuals.css" TITLE="Style">
<title>MarvinSketch Example - Calculating the Lipinski rule of 5 on the fly</title>
</head>

<!--  Important!  -->
<body onUnLoad="document.MSketch=null">

<h1>MarvinSketch Example - Calculating the Lipinski rule of 5 on the fly</h1>

<p>Modify the molecule (delete some atoms or bonds, draw new ones), and watch 
how the calculated fields change.</p>

<p>
<center>
<script LANGUAGE="JavaScript1.1" SRC="../../../marvin.js"></script>
<script LANGUAGE="JavaScript1.1">
<!--
function evaluateChemicalTerms(expression) {
    if(document.MSketch != null) {
        return document.MSketch.evaluateChemicalTerms(expression);
    } else {
        alert("Cannot evaluate expression on molecule:\n"+
              "no JavaScript to Java communication in your browser.\n");
    }
}

function setFields(){
    document.getElementById('mass').innerHTML = evaluateChemicalTerms("mass()");
    document.getElementById('logp').innerHTML = evaluateChemicalTerms("logP()");
    document.getElementById('donorcount').innerHTML = evaluateChemicalTerms("donorCount()");
    document.getElementById('acceptorcount').innerHTML = evaluateChemicalTerms("acceptorCount()");
    document.getElementById('lipinskiruleof5').innerHTML = 
        evaluateChemicalTerms("(mass() <= 500) && (logP() <= 5) && (donorCount() <= 5) && (acceptorCount() <= 10)");
}

function propertyChange(prop) {
    if (prop.indexOf('mol=') !=-1) {
        setFields();
    } 
}

msketch_name = "MSketch";
msketch_mayscript = true;
msketch_begin("../../..", 540, 480);
msketch_param("mol", "../../../mols-2d/caffeine.csmol");
msketch_param("listenpropertychange","true");
msketch_end();
//-->
</script>
<p>
<form NAME="CTForm">
<table border=0>
     <tr>
        <td>Molecular weight:</td>
        <td><div ID="mass"></div></td>
    </tr>
    <tr>
        <td>logP:</td>
        <td><div ID="logp"></div></td>
    </tr>
    <tr>
        <td>H bond donor count:</td>
        <td><div ID="donorcount"></div></td>
    </tr>
    <tr>
        <td>H bond acceptor count:</td>
        <td><div ID="acceptorcount"></div></td>
    </tr>
    <tr>
        <td>Lipinski rule of 5:</td>
        <td><div ID="lipinskiruleof5"></div></td>
    </tr>
</table>
</form>
</center>
<script language="javaScript1.1">
<!--
    setFields();
//-->
</script>

<p>Lipinski rule of 5 is calculated by evaluating 
<a href="../../../help/chemicalterms/ChemicalTerms.html">Chemical Terms</a> 
expressions. When the molecule is changed the Chemical Terms expressions are 
re-evaluated and the results are updated.</p>

<!-- Code highlight BEGIN -->
<link REL ="stylesheet" TYPE="text/css" HREF="../../javacode.css" TITLE="Style">
<blockquote>
<pre>
<span class="comment">&lt;!--  Important!  --&gt;</span>
<span class="keyword">&lt;body</span><span class="normal"> </span><span class="type">onUnLoad</span><span class="symbol">=</span><span class="string">"document.MSketch=null"</span><span class="keyword">&gt;</span>

<span class="keyword">&lt;center&gt;</span>
<span class="keyword">&lt;script</span><span class="normal"> </span><span class="type">LANGUAGE</span><span class="symbol">=</span><span class="string">"JavaScript1.1"</span><span class="normal"> </span><span class="type">SRC</span><span class="symbol">=</span><span class="string">"../../../marvin.js"</span><span class="keyword">&gt;&lt;/script&gt;</span>
<span class="keyword">&lt;script</span><span class="normal"> </span><span class="type">LANGUAGE</span><span class="symbol">=</span><span class="string">"JavaScript1.1"</span><span class="keyword">&gt;</span>
<span class="comment">&lt;!--</span>
<span class="keyword">function</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="normal">expression</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">if</span><span class="symbol">(</span><span class="normal">document</span><span class="symbol">.</span><span class="normal">MSketch </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> document</span><span class="symbol">.</span><span class="normal">MSketch</span><span class="symbol">.</span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="normal">expression</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span><span class="normal"> </span><span class="keyword">else</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="function">alert</span><span class="symbol">(</span><span class="string">"Cannot evaluate expression on molecule:</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">+</span>
<span class="normal">              </span><span class="string">"no JavaScript to Java communication in your browser.</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="cbracket">}</span>

<span class="keyword">function</span><span class="normal"> </span><span class="function">setFields</span><span class="symbol">()</span><span class="cbracket">{</span>
<span class="normal">    document</span><span class="symbol">.</span><span class="function">getElementById</span><span class="symbol">(</span><span class="string">'mass'</span><span class="symbol">).</span><span class="normal">innerHTML </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"mass()"</span><span class="symbol">);</span>
<span class="normal">    document</span><span class="symbol">.</span><span class="function">getElementById</span><span class="symbol">(</span><span class="string">'atomcount'</span><span class="symbol">).</span><span class="normal">innerHTML </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"atomCount()"</span><span class="symbol">);</span>
<span class="normal">    document</span><span class="symbol">.</span><span class="function">getElementById</span><span class="symbol">(</span><span class="string">'ringcount'</span><span class="symbol">).</span><span class="normal">innerHTML </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"ringCount()"</span><span class="symbol">);</span>
<span class="normal">    document</span><span class="symbol">.</span><span class="function">getElementById</span><span class="symbol">(</span><span class="string">'logp'</span><span class="symbol">).</span><span class="normal">innerHTML </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"logP()"</span><span class="symbol">);</span>
<span class="normal">    document</span><span class="symbol">.</span><span class="function">getElementById</span><span class="symbol">(</span><span class="string">'psa'</span><span class="symbol">).</span><span class="normal">innerHTML </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"PSA()"</span><span class="symbol">);</span>
<span class="normal">    document</span><span class="symbol">.</span><span class="normal">CTForm</span><span class="symbol">.</span><span class="normal">name</span><span class="symbol">.</span><span class="normal">value </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"name()"</span><span class="symbol">);</span><span class="normal"> </span>
<span class="normal">    document</span><span class="symbol">.</span><span class="normal">CTForm</span><span class="symbol">.</span><span class="normal">smiles</span><span class="symbol">.</span><span class="normal">value </span><span class="symbol">=</span><span class="normal"> </span><span class="function">evaluateChemicalTerms</span><span class="symbol">(</span><span class="string">"molString('smiles')"</span><span class="symbol">);</span>
<span class="cbracket">}</span>

<span class="keyword">function</span><span class="normal"> </span><span class="function">propertyChange</span><span class="symbol">(</span><span class="normal">prop</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">prop</span><span class="symbol">.</span><span class="function">indexOf</span><span class="symbol">(</span><span class="string">'mol='</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">!=-</span><span class="number">1</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="function">setFields</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span><span class="normal"> </span>
<span class="cbracket">}</span>

<span class="normal">msketch_name </span><span class="symbol">=</span><span class="normal"> </span><span class="string">"MSketch"</span><span class="symbol">;</span>
<span class="normal">msketch_mayscript </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">true</span><span class="symbol">;</span>
<span class="function">msketch_begin</span><span class="symbol">(</span><span class="string">"../../.."</span><span class="symbol">,</span><span class="normal"> </span><span class="number">540</span><span class="symbol">,</span><span class="normal"> </span><span class="number">480</span><span class="symbol">);</span>
<span class="function">msketch_param</span><span class="symbol">(</span><span class="string">"mol"</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"../../../mols-2d/caffeine.csmol"</span><span class="symbol">);</span>
<span class="function">msketch_param</span><span class="symbol">(</span><span class="string">"listenpropertychange"</span><span class="symbol">,</span><span class="string">"true"</span><span class="symbol">);</span>
<span class="function">msketch_end</span><span class="symbol">();</span>
<span class="comment">//--&gt;</span>
<span class="keyword">&lt;/script&gt;</span>
<span class="keyword">&lt;p&gt;</span>
<span class="keyword">&lt;form</span><span class="normal"> </span><span class="type">NAME</span><span class="symbol">=</span><span class="string">"CTForm"</span><span class="keyword">&gt;</span>
<span class="keyword">&lt;table</span><span class="normal"> </span><span class="type">border</span><span class="symbol">=</span><span class="type">0</span><span class="keyword">&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">Molecular weight:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;div</span><span class="normal"> </span><span class="type">ID</span><span class="symbol">=</span><span class="string">"mass"</span><span class="keyword">&gt;&lt;/div&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">Atom count:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;div</span><span class="normal"> </span><span class="type">ID</span><span class="symbol">=</span><span class="string">"atomcount"</span><span class="keyword">&gt;&lt;/div&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">Ring count:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;div</span><span class="normal"> </span><span class="type">ID</span><span class="symbol">=</span><span class="string">"ringcount"</span><span class="keyword">&gt;&lt;/div&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">Polar surface area:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;div</span><span class="normal"> </span><span class="type">ID</span><span class="symbol">=</span><span class="string">"psa"</span><span class="keyword">&gt;&lt;/div&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">logP:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;div</span><span class="normal"> </span><span class="type">ID</span><span class="symbol">=</span><span class="string">"logp"</span><span class="keyword">&gt;&lt;/div&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">IUPAC name:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;textarea</span><span class="normal"> </span><span class="type">NAME</span><span class="symbol">=</span><span class="string">"name"</span><span class="normal"> </span><span class="type">ROWS</span><span class="symbol">=</span><span class="type">2</span><span class="normal"> </span><span class="type">COLS</span><span class="symbol">=</span><span class="type">60</span><span class="normal"> </span><span class="type">READONLY</span><span class="symbol">=</span><span class="string">"readonly"</span><span class="keyword">&gt;&lt;/textarea&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;tr&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;</span><span class="normal">SMILES:</span><span class="keyword">&lt;/td&gt;</span>
<span class="normal">        </span><span class="keyword">&lt;td&gt;&lt;textarea</span><span class="normal"> </span><span class="type">NAME</span><span class="symbol">=</span><span class="string">"smiles"</span><span class="normal"> </span><span class="type">ROWS</span><span class="symbol">=</span><span class="type">2</span><span class="normal"> </span><span class="type">COLS</span><span class="symbol">=</span><span class="type">60</span><span class="normal"> </span><span class="type">READONLY</span><span class="symbol">=</span><span class="string">"readonly"</span><span class="keyword">&gt;&lt;/textarea&gt;&lt;/td&gt;</span>
<span class="normal">    </span><span class="keyword">&lt;/tr&gt;</span>
<span class="keyword">&lt;/table&gt;</span>
<span class="keyword">&lt;/form&gt;</span>
<span class="keyword">&lt;/center&gt;</span>
<span class="keyword">&lt;script</span><span class="normal"> </span><span class="type">language</span><span class="symbol">=</span><span class="string">"javaScript1.1"</span><span class="keyword">&gt;</span>
<span class="comment">&lt;!--</span>
<span class="function">    setFields</span><span class="symbol">();</span>
<span class="comment">//--&gt;</span>
<span class="keyword">&lt;/script&gt;</span>

<span class="keyword">&lt;/body&gt;</span>
</pre>
</blockquote>
<!-- Code highlight END -->

<center><div class="lenia">&nbsp;</div></center>
</body>
</html>
